
package character_5;

import static java.lang.System.in;
import static java.lang.System.out;

class Some {
    void method(int s){
        System.out.println("这是int的");
    }
    
    void method(Integer s){
        System.out.println("这是Integer的");
    }
}

public class Character_5 {
    private int a;
    private String s = "s";
    static {
        //static方法或区块中不可以出现this关键字
        System.out.println("haha");
    }
    {
        System.out.println("初始化");
    }
    
    public Character_5(int a){
        this.a = a;
        this.x = a;
        System.out.println("无参构造函数");
    }
    
    public Character_5(int a, String s) {
        this(a);//一个构造方法中调用另一个，只在第一行中
        this.s = s;
        //System.out.print(this.a + this.s);
        System.out.println("有参构造函数");
    }
    final int x;//后面必须初始化
    
    public static int sum(int a, int... num){//不定长自变量,必须放在最后面
        int sum = 0;
        for (int i : num) {
            sum += i;
        }
        return sum;
    }
    
    class Inner{
    }
    static class Other{
        int a = Character_5.sum(121, 121);//可存取外部类静态成员
    }
    
    //static方法或区块中不可以出现this关键字,也不可引用非静态的成员变量
    public static void main(String[] args) {
        Some s = new Some();
        s.method(1);
        s.method(new Integer(1));//两种不一样
        
        new Character_5(110, "dongyanan");
        
        out.println("插入了静态了");
        
        out.println(Character_5.sum(250, 520, 205, 502));
        
        Character_5 c = new Character_5(0);
        Character_5.Inner in = c.new Inner();//内部类的声明方法
        
        Character_5.Other o = new Other();//静态内部类声明方法
        
        class a{}//方法中也可定义类，外部不能用
        
        Object object = new Object(){//匿名内部类
            public String toString(){
                return "无聊的示范而已";
            }
        };
        
        System.out.println(object.toString());
        
        Customer c1 = new Customer("张三");
        some(c1);
        System.out.println(c1.name);
        
        Customer c2 = new Customer("赵六");
        other(c2);
        System.out.println(c2.name);
        
        System.out.println(Test.create());
        
        
     
    }
    static void test(int... x){}
    
    
    static void some(Customer c){
        c.name = "李四";
    }
    static void other(Customer c){
        c = new Customer("王五");//建立新对象指定给c参考，原本参考的对象会被清除
    }
    
}
class Customer{
    String name;

    public Customer(String name) {
        this.name = name;
    }
   
}

